package com.appdupe.flamer.adapter;
import org.json.JSONArray;
import org.json.JSONException;

import com.appdupe.flamernofb.R;
import com.google.gson.JsonArray;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridEventosAdapter extends BaseAdapter {
 
        private Context context;
        private final String[] gridValues;
        private JSONArray dados;
        //Constructor to initialize values
        public GridEventosAdapter(Context context, String[ ] gridValues) {
 
            this.context        = context;
            this.gridValues     = gridValues;
        }
        
        public GridEventosAdapter(Context context, JSONArray arra) {
        	this.gridValues = null;
            this.context        = context;
            this.dados = arra;
           
            try{
            	Log.i("TAG","TESTE"+arra.getJSONObject(0).get("name"));
            }catch(JSONException e){
				Log.i("TAG", "ERROR:"+e.getMessage());
			}
        }
         
         
       

		@Override
        public int getCount() {
             
            // Number of times getView method call depends upon gridValues.length
            return gridValues.length;
        }
     
        @Override
        public Object getItem(int position) {
            return null;
        }
     
        @Override
        public long getItemId(int position) {
             
            return 0;
        }
         
         
        // Number of times getView method call depends upon gridValues.length
         
        public View getView(int position, View convertView, ViewGroup parent) {
        	//return null;
        	 
            // LayoutInflator to call external grid_item.xml file
             
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     
            View gridView;
     
            if (convertView == null) {
     
                gridView = new View(context);
     
                // get layout from grid_item.xml ( Defined Below )
 
                gridView = inflater.inflate( R.layout.gridevento_item , null);
     
                // set value into textview
                 
                TextView textView = (TextView) gridView
                        .findViewById(R.id.grid_item_label);
 
                textView.setText(gridValues[position]);
     
                // set image based on selected text
                 
                ImageView imageView = (ImageView) gridView
                        .findViewById(R.id.grid_item_image);
     
                String arrLabel = gridValues[ position ];
     
                if (arrLabel.equals("Windows")) {
                     
                    imageView.setImageResource(R.drawable.abs__ab_bottom_solid_dark_holo);
                     
                } else if (arrLabel.equals("iOS")) {
                     
                    imageView.setImageResource(R.drawable.abs__ab_bottom_solid_inverse_holo);
                     
                } else if (arrLabel.equals("Blackberry")) {
                     
                    imageView.setImageResource(R.drawable.abs__ab_bottom_solid_light_holo);
                     
                } else {
                     
                    imageView.setImageResource(R.drawable.abs__ab_bottom_transparent_dark_holo);
                }
     
            } else {
 
               gridView = (View) convertView;
            }
     
            return gridView;
        }
        	
        

		
}